package com.springbootproduct.service.impl;

import com.codingapi.txlcn.tc.annotation.DTXPropagation;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.springbootproduct.entity.User;
import com.springbootproduct.mapper.UserMapper;
import com.springbootproduct.service.HelloService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HelloServiceImpl implements HelloService {
    @Resource
    UserMapper userMapper;

    public String sayHello(String name){
        return "helloWorld,hello"+name; // 提供一个hello World
    }
    public List<User> list(){
       return  userMapper.getAll();
    }

    @Transactional
    @LcnTransaction(propagation = DTXPropagation.SUPPORTS)
    public void save(User user){
        try {
            userMapper.save(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Transactional
    @LcnTransaction
    public void update(){
        try {
            userMapper.update();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
